<?php
namespace app\index\controller;

use app\common\nimble\Logic as bLogic;
use app\common\nimble\model as bModel;
use app\index\nimble\Logic;
use think\App;
use think\Controller;
use think\Facade\Request;

class Base extends Controller
{

    protected $params;
    protected $assign = [];


    public function __construct(App $app = null)
    {
        parent::__construct($app);
        $this->params = $this->parseParams();

        $this->assign['right_tag'] = $this->logic()->tag()->getHotTag();
        $this->assign['right_month'] = $this->logic()->article()->getNumListByMonth();
        $this->assign['right_category'] = $this->logic()->article()->getNumListCategory();
        $this->assign('base', json_encode($this->assign));
    }

    protected function parseParams()
    {
        $data = Request::param(true);
        if (empty($data)) {
            $data = file_get_contents("php://input"); // 未解决 前端使用json格式传入数据
        }
        return $data;
    }

    // 载入公用逻辑链式操作
    public function bLogic()
    {
        $class = new bLogic();
        return $class;
    }

    // 载入公用模型链式操作
    public function bModel()
    {
        $class = new bModel();
        return $class;
    }

    // 载入当前的逻辑链式操作
    public function logic()
    {
        $class = new Logic();
        return $class;
    }

    // 将不存在的类的方法指向common中的logic 用于转移了类的方法
    public function __call($name, $argv)
    {
        $className = get_called_class(); // 获取当前主调的类名 (这是完整的类名)
        $className = '\\app\\common\\logic'.strrchr($className, '\\');
        $class = new $className;
        return call_user_func_array([$class, $name], $argv);
    }


}